package com.sgj.springcloud.alibaba.service.impl;

import com.sgj.springcloud.alibaba.dao.AccountDao;
import com.sgj.springcloud.alibaba.service.AccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @author 沈国纪
 * @date 2021/6/6 12:24
 */
@Service
public class AccountServiceImpl implements AccountService {

	private static final Logger LOGGER = LoggerFactory.getLogger(AccountServiceImpl.class);

	@Autowired
	private AccountDao accountDao;

	/**
	 * 扣减账户余额
	 */
	@Override
	public void decrease(Long userId, BigDecimal money) {
		LOGGER.info("-------> account-service中扣减账户余额开始");
		try { TimeUnit.SECONDS.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); }
		accountDao.decrease(userId,money);
		LOGGER.info("-------> account-service中扣减账户余额结束");
	}
}